const https = require('https');
const fs = require('fs');
const WebSocket = require('ws');

// 读取SSL证书
const server = https.createServer({
  cert: fs.readFileSync('/Users/flynn/websocket/wss/cert.pem'),
  key: fs.readFileSync('/Users/flynn/websocket/wss/key.pem')
});

// 创建WebSocket服务器绑定到HTTPS
const wss = new WebSocket.Server({ server });

// 监听3000端口
server.listen(3000, () => {
  console.log('WSS Server running on port 3000');
});

// 保持原有connection和message处理逻辑
wss.on('connection', (ws) => {
  console.log(`[SERVER] connection()`);
  ws.on('message', (message) => {
    console.log(`[SERVER] Received: ${message}`);
    ws.send(`message from server: ${message}`);
  });
});
